//
//  BannerAdViewController.h
//  tapburstfree
//
//  Created by Limin on 12-9-4.
//  Copyright HappyBluefin 2012年. All rights reserved.
//

#import "BannerAdViewController.h"
#import "AppController.h"
#import "HBKeys.h"

@implementation BannerAdViewController

@synthesize adView, adViewFull;

- (void)dealloc {
	adView.delegate = nil;
	adView.adWebBrowswerDelegate = nil;
	
	adViewFull.delegate = nil;
	adViewFull.adWebBrowswerDelegate = nil;
	[super dealloc];
}

- (void)didReceiveMemoryWarning {
	[super didReceiveMemoryWarning];
}

#pragma mark - View lifecycle

- (void)viewDidLoad {
	[super viewDidLoad];

	AdViewType type;
	NSString* key;
	
	if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
	{
		type = AdViewTypeLargeBanner;
		key = [NSString stringWithFormat:@"%s", kAdsMogoKey_iPad];
	}
	else
	{
		type = AdViewTypeNormalBanner;
		key = [NSString stringWithFormat:@"%s", kAdsMogoKey];
	}
	
	adView = [[AdMoGoView alloc] initWithAppKey:key adType:type expressMode:NO adMoGoViewDelegate:self];
	adView.adWebBrowswerDelegate = self;
	adView.frame = CGRectZero;
	[self.view addSubview:adView];
	[adView release];
	
	adViewFull = [[AdMoGoView alloc] initWithAppKey:key adType:AdViewTypeFullScreen expressMode:NO adMoGoViewDelegate:self];
	adViewFull.adWebBrowswerDelegate = self;
	adViewFull.frame = CGRectZero;
	[self.view addSubview:adView];
	[adViewFull release];
}

- (void)viewDidUnload {
	[super viewDidUnload];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
	return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Ads delegate 
- (UIViewController *)viewControllerForPresentingModalView {
	return self;
}

- (void)adMoGoDidStartAd:(AdMoGoView *)adMoGoView {
//	NSLog(@"广告开始请求回调");
}

- (void)adMoGoDidReceiveAd:(AdMoGoView *)adMoGoView {
//	NSLog(@"广告接收成功回调");
	CGRect bounds = [[UIScreen mainScreen] applicationFrame];
	CGRect rc = adMoGoView.frame;
	rc.origin.x = (bounds.size.width - rc.size.width) / 2;
	rc.origin.y = (bounds.size.height - rc.size.height);
	adMoGoView.frame = rc;
}

- (void)adMoGoDidFailToReceiveAd:(AdMoGoView *)adMoGoView didFailWithError:(NSError *)error {
//	NSLog(@"广告接收失败回调");
}

- (void)adMoGoClickAd:(AdMoGoView *)adMoGoView {
//	NSLog(@"点击广告回调");
}

- (void)adMoGoDeleteAd:(AdMoGoView *)adMoGoView {
//	NSLog(@"广告关闭回调");
}

-(void)adMoGoFullScreenAdReceivedRequest
{
	NSLog(@"全屏广告接收成功");
}

- (void)adMoGoFullScreenAdFailedWithError:(NSError*) error
{
	NSLog(@"全屏广告接收失败");
}

- (void)adMoGoWillPresentFullScreenAdModal
{
	NSLog(@"全屏广告展示");
}

- (void)adMoGoDidDismissFullScreenAdModal
{
	NSLog(@"全屏广告消失");
}

#pragma mark -
#pragma mark AdMoGoWebBrowserControllerUserDelegate delegate 

- (void)webBrowserWillAppear {
//    NSLog(@"浏览器将要展示");
}

- (void)webBrowserDidAppear {
//    NSLog(@"浏览器已经展示");
}

- (void)webBrowserWillClosed {
//    NSLog(@"浏览器将要关闭");
}

- (void)webBrowserDidClosed {
//    NSLog(@"浏览器已经关闭");
}

- (void)webBrowserShare:(NSString *)url {
	
}

@end
